package com.eece496.Server;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eece496.Database.Enrollment;
import com.eece496.Database.TAEnrollment;
import com.eece496.Helpers.StudentInfo;
import com.eece496.Helpers.TAInfo;

/**
 * Servlet implementation class ProfViewClassList
 */
public class ProfViewClassListServlet extends MasterServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ProfViewClassListServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Connect();
		try {
			String firstname = request.getParameter("firstname");
			String lastname = request.getParameter("lastname");
			String courseNumber = request.getParameter("courseNumber");
			String sectionNumber = request.getParameter("sectionNumber");

			Enrollment EnrollmentDB = new Enrollment();
			EnrollmentDB.Setup(connection);

			TAEnrollment TAEnrollmentDB = new TAEnrollment();
			TAEnrollmentDB.Setup(connection);

			ArrayList<StudentInfo> sInfo = new ArrayList<StudentInfo>();
			ArrayList<TAInfo> tInfo = new ArrayList<TAInfo>();

			sInfo = EnrollmentDB.GetAllStudentsEnrolled(courseNumber,
					sectionNumber);
			
			tInfo = TAEnrollmentDB.GetAllTAsEnrolled(courseNumber,
					sectionNumber);

			request.setAttribute("firstname", firstname);
			request.setAttribute("lastname", lastname);
			request.setAttribute("courseNumber", courseNumber);
			request.setAttribute("sectionNumber", sectionNumber);
			request.setAttribute("StudentInfo", sInfo);
			request.setAttribute("TAInfo", tInfo);
			request.getRequestDispatcher(
					"/Professor/Professor-View-Class-List.jsp").forward(
					request, response);

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
